package com.scnu.hachimi.element;

import com.scnu.hachimi.manager.ObjectManager;
import com.scnu.hachimi.manager.ResourcesManager;

import java.awt.*;

public class Bot extends Tank {
    private Color color;  //子弹颜色
    private long loadTime;
    public int hp;
    private int atk;
    private int bulletSpeed;
    private int bulletSize;
    private long lastFireTime = 0;

    public boolean isBOSS = false;

    private int mc;  //移动次数
    private Direction md;  //移动方向

    public Bot(String img, int x, int y, int width, int height,
               int speed, int atk, long loadTime, int bulletSpeed, int bulletSize,
               String upImg, String downImg, String leftImg, String rightImg,
               Color color, int hp, ObjectManager om) {

        super(img, x, y, width, height, speed, upImg, downImg, leftImg, rightImg, om);
        this.color = color;
        this.hp = hp;
        this.loadTime = loadTime;
        this.atk = atk;
        this.bulletSpeed = bulletSpeed;
        this.bulletSize = bulletSize;
    }

    @Override
    public void paintSelf(Graphics g, ResourcesManager rm) {
        Image img = rm.imageMap.get(this.img);
        g.drawImage(img, x, y, null);
    }

    @Override
    public Rectangle getRect() {
        return new Rectangle(x + 4, y + 4, w - 8, h - 8);
    }

    //随机方向和移动次数
    public void randomD_C() {
        md = Direction.values()[(int) (Math.random() * 4)];
        mc = (int) (Math.random() * 120) + 1;
        sm = true;

        if (Math.random() < 0.05) md = null;
    }
    boolean sm = true;
    public void autoMoveAndAttack() {
        //随机射击
        if (System.currentTimeMillis() - lastFireTime >= loadTime && Math.random() < 0.01) {
            lastFireTime = System.currentTimeMillis();
            Point headPoint = getHeadPoint();
            om.bullet.add(new Bullet("", headPoint.x, headPoint.y, bulletSize, bulletSize, bulletSpeed, atk, direct, color,  false));
        }


        //随机移动
        if (mc <= 0 || !sm) randomD_C();
        if (md != null) {
            setImg(md);
            sm = move(md);
        }
        mc--;
    }
}
